package com.zhongkun.datahome.service.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongkun.datahome.service.constant.MaterialTypeEnum;
import com.zhongkun.datahome.service.domain.HouseBuildPlan;
import com.zhongkun.datahome.service.domain.HouseMaterial;
import com.zhongkun.datahome.service.mapper.HouseBuildPlanMapper;
import com.zhongkun.datahome.service.mapper.HouseMaterialMapper;
import com.zhongkun.datahome.service.req.qry.material.HouseMaterialQry;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @Author: lifengsheng
 * @Date: 2025/4/14 17:15
 * @Desc
 */
@Repository
public class HouseMaterialRepository extends ServiceImpl<HouseMaterialMapper, HouseMaterial> {
    public void removeByHouseIds(List<Long> houseIds) {
        if (CollectionUtils.isNotEmpty(houseIds)) {
            this.remove(new LambdaQueryWrapper<HouseMaterial>()
                    .in(HouseMaterial::getHouseId, houseIds));
        }
    }

    public List<String> listRoom(Long houseId) {
        return this.list(new LambdaQueryWrapper<HouseMaterial>()
                .select(HouseMaterial::getRoom)
                .eq(HouseMaterial::getHouseId, houseId))
                .stream()
                .map(HouseMaterial::getRoom)
                .distinct()
                .collect(Collectors.toList());
    }

    public List<HouseMaterial> listBy(HouseMaterialQry qry) {
        return this.getBaseMapper().listBy(qry);
    }

    public List<HouseMaterial> listByHouseId(Long houseId) {
        return this.list(new LambdaQueryWrapper<HouseMaterial>()
                .eq(HouseMaterial::getHouseId, houseId));
    }

    public List<HouseMaterial> listBySkuId(Long skuId) {
        return this.list(new LambdaQueryWrapper<HouseMaterial>()
                .eq(HouseMaterial::getMaterialType, MaterialTypeEnum.COMMON_SKU.getType())
                .eq(HouseMaterial::getMaterialId, skuId));
    }
}
